package cn.springcloud.fix.common.core.condition;

import org.springframework.boot.autoconfigure.condition.ConditionMessage;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.util.StringUtils;

public class MybatisPlusCondition extends SpringBootCondition {

    @Override
    public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
        ConditionMessage.Builder message = ConditionMessage.forCondition("MybatisPlus Condition");
        Environment environment = context.getEnvironment();
        String key = environment.getProperty("mybatis-plus.type-aliases-package");
        if (StringUtils.hasText(key)) {
            return ConditionOutcome.match(message.foundExactly("MybatisPlus location"));
        }
        return ConditionOutcome.noMatch(message.didNotFind("MybatisPlus location").atAll());
    }
}
